var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pjlist: [],
    now_page:1,
    totalpage:'',
    type:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.setData({
        type:options.type
      })
      this.getpingjia();
  },
  previewImage(e){
    console.log(e)
    let index = e.currentTarget.dataset.index;
    let url = e.currentTarget.dataset.url;
    let commentList = this.data.pjlist;
    wx.previewImage({
      current: url, // 当前显示图片的http链接
      urls: commentList[index].imgs // 需要预览的图片http链接列表
    })
  },
  delData(e){
    wx.showModal({
      cancelColor: '#999',
      title:'提示',
      content:'是否确认删除该评价？',
      success:r=>{
        if(r.confirm){
          let index = e.target.dataset.index;
          let list = this.data.pjlist;
          let url;
          if (this.data.type == 0) url ="api/userr/delEvaluation";
          if (this.data.type == 1) url ="api/userr/delOilEvaluation";
          if (this.data.type == 2) url ="api/userr/delCarEvaluation";
          app.post({
            url:url,
            data:{
              id:list[index].id
            },
            success:res=>{
              if(res.data.code == 1){
                wx.showToast({
                  title: '删除成功',
                })
                list.splice(index,1);
                this.setData({
                  pjlist:list
                })
              }else{
                wx.showToast({
                  title: '删除失败',
                })
              }
            }
          })
        }
      }
    })
    
  },
  getpingjia(){
    var that = this;
    var userid = wx.getStorageSync("userId");
    let type = this.data.type;
    let url="";
    if(type == 0) url= "api/user/myEvaluation";
    if(type == 1) url="api/userr/oilCommentList";
    if(type == 2) url="api/userr/carCommentList";
    var param = {
      url:url,
      data: {
        user_id: userid,
        now_page: 1,
      },
      success: function (e) {
        console.log(e)
        that.setData({
          pjlist: e.data.data.list,
          totalpage:e.data.data.total_page
        })
      },
    };
    app.post(param);
  },
  goDetail(){
      let url = "/pages/mine/order-detail/order-detail?id={{item.id}}" 
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  onReachBottom: function () {
    var that = this;
    // 显示加载图标
   
    // 页数+1
    var now_page = parseInt(that.data.now_page)+1;
    if (now_page > parseInt(that.data.totalpage)) {
      wx.showToast({
        title: '没有更多数据了',
        icon: "none",
        duration: 2000
      })
      return false;
    } else {
      wx.showLoading({
        title: '玩命加载中',
      })
    var userid = wx.getStorageSync("userId");
    var param = {
      url: "api/user/myEvaluation",
      data: {
        user_id: userid,
        now_page: now_page
      },
      success: function (e) {
        that.setData({
          pjlist: that.data.pjlist.concat(e.data.data.list),
          now_page: now_page
        })
        // 隐藏加载框
        wx.hideLoading();

      },
    };
    app.post(param);
    }
  },


})